import { Controller, Get, Post, Body, BadRequestException, Req } from '@nestjs/common';
import { Request } from '@common/auth';
import { UserFocusPhotosService } from './userFocusPhotos.service';
import { FocusUserFocusPhotosDto } from './dto/focus-userFocusPhotos.dto';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { isMongoId } from 'class-validator';
import { ListUserFocusPhotosDto } from './dto/list-userFocusPhotos.dto';
@ApiTags('userFocusPhotos')
@ApiBearerAuth()
@Controller()
export class UserFocusPhotosController {
    constructor(private readonly userFocusPhotosService: UserFocusPhotosService) {}

    @ApiOperation({ summary: '用户点赞作品' })
    @Post('/userFocusPhotos/focus')
    async focus(@Body() input: FocusUserFocusPhotosDto, @Req() req: Request) {
        if (!isMongoId(input.photos)) {
            throw new BadRequestException('id错误！');
        }
        try {
            return await this.userFocusPhotosService.focus(input, req.user);
        } catch (e) {
            throw new BadRequestException('请求失败', e?.message);
        }
    }
    @ApiOperation({ summary: '用户取消点赞作品' })
    @Post('/userFocusPhotos/unfocus')
    async unfocus(@Body() input: FocusUserFocusPhotosDto, @Req() req: Request) {
        if (!isMongoId(input.photos)) {
            throw new BadRequestException('id错误！');
        }
        try {
            return await this.userFocusPhotosService.unfocus(input, req.user);
        } catch (e) {
            throw new BadRequestException('请求失败', e?.message);
        }
    }
    @ApiOperation({ summary: '获取当前用户喜欢列表' })
    @Post('/userFocusPhotos/list')
    list(@Body() dto: ListUserFocusPhotosDto, @Req() req: Request) {
        return this.userFocusPhotosService.list(dto, req.user);
    }
}
